package com.soda.dao.impl;

import java.sql.SQLException;

import com.soda.bean.Contact;
import com.soda.dao.BaseDao;
import com.soda.dao.ContactDao;

public class ContactDaoImpl extends BaseDao implements ContactDao {

	public Contact contact() {
		try {
			getConnection();
			String sql = "select * from contact";
			pt = conn.prepareStatement(sql);
			res = pt.executeQuery();
			if (res.next()) {
				Contact ct = new Contact(res.getInt(1), res.getString(2),
						res.getString(3), res.getString(4), res.getString(5));
				return ct;
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} finally {
			close();
		}

		return null;
	}

	public int update(String phone, String neirong) {
		 try {
			getConnection();
			 String sql="update contact set con_phone=?,con_content=?";
			 pt=conn.prepareStatement(sql);
			 pt.setString(1, phone);
			 pt.setString(2,neirong);
			 
			 return pt.executeUpdate();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally{
			close();
		}
		return 0;
	}
}
